package com.gsn.common;

import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.GsnImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.gsn.desktop.engine.ActorUtility;
import com.gsn.engine.gdx.GsnParticleActor;
import com.gsn.engine.myplay.GsnLayer;
import com.gsn.poker.asset.PortalTexture;

public class SettingGroup extends Group{
	
	GsnImageButton sound;
	GsnImageButton vibrate;
	protected ParticleEffect clickEff;
	GsnLayer layer;
	public SettingGroup(GsnLayer parent)
	{
		PortalTexture portalTexture = PortalTexture.inst();
		
		layer = parent;
		Image bg = new Image(portalTexture.bgSetting);
		portalTexture.scaleActor(bg);
		addActor(bg);
		width = bg.width;
		height = bg.height;
		
		vibrate = new GsnImageButton(portalTexture.vibrateButton, portalTexture.vibrateButton, portalTexture.vibrateButtonPress);
		float pad = (bg.height - 2 * vibrate.getRealHeight())/4;
		portalTexture.scaleActor(vibrate);
		addActor(vibrate);
		vibrate.setClickListener(new ClickListener() {
			
			@Override
			public void click(Actor actor, float x, float y) {
				// TODO Auto-generated method stub
				if (clickEff != null) {
					Vector2 v = ActorUtility.getCoordinate(actor, x, y, layer.getRoot());
					GsnParticleActor par = new GsnParticleActor(clickEff);
					par.setPostition(v.x, v.y);
					par.start();
					layer.addActor(par);
					Settings.enableSound = !Settings.enableSound;
				}
			}
		});
		vibrate.x = (bg.width - vibrate.getRealWidth())/2;
		vibrate.y = pad;
		
		sound = new GsnImageButton(portalTexture.soundButton, portalTexture.soundButton, portalTexture.soundButtonPress);
		portalTexture.scaleActor(sound);
		addActor(sound);
		sound.setClickListener(new ClickListener() {
			
			@Override
			public void click(Actor actor, float x, float y) {
				// TODO Auto-generated method stub
				if (clickEff != null) {
					Vector2 v = ActorUtility.getCoordinate(actor, x, y, layer.getRoot());
					GsnParticleActor par = new GsnParticleActor(clickEff);
					par.setPostition(v.x, v.y);
					par.start();
					layer.addActor(par);
					Settings.enableSound = !Settings.enableSound;
				}
				
			}
		});
		
		sound.x = vibrate.x;
		sound.y = vibrate.y + sound.height + pad;
		vibrate.setChecked(!Settings.enableVibrate);
		sound.setChecked(!Settings.enableSound);
		clickEff = PortalTexture.inst().clickEff;
	}
	
}
